﻿using System;
using UnityEngine;

// Token: 0x0200002E RID: 46
public class WoundBehaviour : MonoBehaviour
{
	// Token: 0x060000C6 RID: 198 RVA: 0x00010720 File Offset: 0x0000E920
	private void Start()
	{
		this.currentTex = base.GetComponent<SpriteRenderer>().sprite.texture;
		Texture2D texture2D = this.rotateTexture(base.GetComponent<SpriteRenderer>().sprite.texture, 0f);
		Sprite sprite = Sprite.Create(texture2D, base.GetComponent<SpriteRenderer>().sprite.rect, Vector2.one * 0.5f, 14f);
		texture2D.filterMode = FilterMode.Point;
		base.GetComponent<SpriteRenderer>().sprite = sprite;
	}

	// Token: 0x060000C7 RID: 199 RVA: 0x0001079C File Offset: 0x0000E99C
	private void Update()
	{
		if (Input.GetKeyDown(KeyCode.Space))
		{
			this.rot += 10;
			Texture2D texture2D = this.rotateTexture(this.currentTex, (float)this.rot);
			base.GetComponent<SpriteRenderer>().sprite.texture.SetPixels(texture2D.GetPixels());
			base.GetComponent<SpriteRenderer>().sprite.texture.Apply();
		}
	}

	// Token: 0x060000C8 RID: 200 RVA: 0x00010808 File Offset: 0x0000EA08
	private Texture2D rotateTexture(Texture2D tex, float angle)
	{
		Texture2D texture2D = new Texture2D(tex.width, tex.height);
		int width = tex.width;
		int height = tex.height;
		float num = this.rot_x(angle, (float)(-(float)width) / 2f, (float)(-(float)height) / 2f) + (float)width / 2f;
		float num2 = this.rot_y(angle, (float)(-(float)width) / 2f, (float)(-(float)height) / 2f) + (float)height / 2f;
		float num3 = this.rot_x(angle, 1f, 0f);
		float num4 = this.rot_y(angle, 1f, 0f);
		float num5 = this.rot_x(angle, 0f, 1f);
		float num6 = this.rot_y(angle, 0f, 1f);
		float num7 = num;
		float num8 = num2;
		for (int i = 0; i < tex.width; i++)
		{
			float num9 = num7;
			float num10 = num8;
			for (int j = 0; j < tex.height; j++)
			{
				num9 += num3;
				num10 += num4;
				texture2D.SetPixel((int)Mathf.Floor((float)i), (int)Mathf.Floor((float)j), this.getPixel(tex, num9, num10));
			}
			num7 += num5;
			num8 += num6;
		}
		texture2D.Apply();
		return texture2D;
	}

	// Token: 0x060000C9 RID: 201 RVA: 0x00010940 File Offset: 0x0000EB40
	private Color getPixel(Texture2D tex, float x, float y)
	{
		int num = (int)Mathf.Floor(x);
		int num2 = (int)Mathf.Floor(y);
		Color result;
		if (num > tex.width || num < 0 || num2 > tex.height || num2 < 0)
		{
			result = Color.clear;
		}
		else
		{
			result = tex.GetPixel(num, num2);
		}
		return result;
	}

	// Token: 0x060000CA RID: 202 RVA: 0x0001098C File Offset: 0x0000EB8C
	private float rot_x(float angle, float x, float y)
	{
		float num = Mathf.Cos(angle / 180f * 3.1415927f);
		float num2 = Mathf.Sin(angle / 180f * 3.1415927f);
		return x * num + y * -num2;
	}

	// Token: 0x060000CB RID: 203 RVA: 0x000109C8 File Offset: 0x0000EBC8
	private float rot_y(float angle, float x, float y)
	{
		float num = Mathf.Cos(angle / 180f * 3.1415927f);
		float num2 = Mathf.Sin(angle / 180f * 3.1415927f);
		return x * num2 + y * num;
	}

	// Token: 0x040001C5 RID: 453
	private Sprite origSprite;

	// Token: 0x040001C6 RID: 454
	private Texture2D currentTex;

	// Token: 0x040001C7 RID: 455
	private int rot;
}
